#pragma once
#include<iostream>
#include<cstring>
#include<unistd.h>
using namespace std;

namespace ns_task
{
    class Task
    {
    public:
        Task(int sock = -1)
            :new_sock(sock)
        {}
        void Run()
        {
            //while(true)
            //{
                //提供一个短服务
                char buffer[1024];
                memset(buffer, 0, sizeof(buffer));
                ssize_t s = read(new_sock, buffer, sizeof(buffer) - 1);
                if(s > 0)
                {
                    buffer[s] = 0;//将我们获取的内容当成字符串
                    cout << "client# " << buffer << endl;
                    string echo_string = ">>>server<<<, ";
                    echo_string += buffer;

                    write(new_sock, echo_string.c_str(), echo_string.size());
                }
                else if(s == 0)
                {
                    cout << "client quit ... " << endl;
                    //break;
                }
                else
                {
                    cout << "read error ... " << endl;
                    //break;
                }
           //}

           close(new_sock);
        }
        ~Task()
        {}
    private:
        int new_sock;
    };  
}
